home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / clang / ebksrc.zip / PCFRAME.CPP < prev    next >
C/C++ Source or Header  |  1991-07-30  |  4KB  |  168 lines

  1. /*
  2.  
  3.     pcframe.cpp
  4.     7-30-91
  5.     Text mode framing for the IBM PC.
  6.  
  7.     Copyright 1991
  8.     John W. Small
  9.     All right reserved
  10.     Use freely but acknowledge authorship and copyright.
  11.  
  12.     PSW / Power SoftWare
  13.     P.O. Box 10072
  14.     McLean, Virginia 22102 8072 USA
  15.     
  16.     John Small
  17.     Voice: (703) 759-3838
  18.     CIS: 73757,2233
  19.  
  20. */
  21.  
  22.  
  23. #include <conio.h>
  24. #include <pcframe.hpp>
  25.  
  26. unsigned char TextFraming::frame[] =
  27.     "\263\304\332\302\277\264\331\301\300\303\305"
  28.     "\272\315\311\313\273\271\274\312\310\314\316"
  29.     "\263\315\325\321\270\265\276\317\324\306\330"
  30.     "\272\304\326\322\267\266\275\320\323\307\327";
  31.  
  32. int TextFraming::buf[MAX_TF_BUF];
  33. struct text_info TextFraming::ti;
  34.  
  35. TextFraming PCF;
  36.  
  37. int TextFraming::puttext(int l, int t, int r, int b,
  38.     void *buf)
  39. {
  40.     if (validDimensions(l,t,r,b))
  41.         return ::puttext(l,t,r,b,buf);
  42.     return 0;
  43. }
  44.  
  45. int TextFraming::validDimensions(int left, int top,
  46.     int right, int bottom)
  47. {
  48.     if (left < 1 || left > right
  49.         || right > ti.screenwidth ||
  50.         top < 1 || top > bottom
  51.         || bottom > ti.screenheight)
  52.         return 0;
  53.     return 1;
  54. }
  55.  
  56. int TextFraming::validateDimensions(int& left, int& top,
  57.     int& right, int& bottom, unsigned minWidth,
  58.     unsigned minHeight)
  59. {
  60.     int l, t, r, b, tmp;
  61.  
  62.     if (minWidth < 1 || minWidth > ti.screenwidth
  63.         || minHeight < 1
  64.         || minHeight > ti.screenheight)
  65.         return 0;
  66.     l = left;
  67.     if (l < 1)
  68.         l = 1;
  69.     else if (l > ti.screenwidth)
  70.         l = ti.screenwidth;
  71.     r = right;
  72.     if (r < 1)
  73.         r = 1;
  74.     else if (r > ti.screenwidth)
  75.         r = ti.screenwidth;
  76.     if (l > r)  {
  77.         tmp = l;
  78.         l = r;
  79.         r = tmp;
  80.     }
  81.     if ((tmp = l + minWidth - 1) > r)
  82.         if (tmp > ti.screenwidth)
  83.             r = ti.screenwidth;
  84.         else
  85.             r = tmp;
  86.     if ((tmp = r - minWidth + 1) < l)
  87.         if (tmp < 1)
  88.             return 0;
  89.         else
  90.             l = tmp;
  91.     t = top;
  92.     if (t < 1)
  93.         t = 1;
  94.     else if (t > ti.screenheight)
  95.         t = ti.screenheight;
  96.     b = bottom;
  97.     if (b < 1)
  98.         b = 1;
  99.     else if (b > ti.screenheight)
  100.         b = ti.screenheight;
  101.     if (t > b)  {
  102.         tmp = t;
  103.         t = b;
  104.         b = tmp;
  105.     }
  106.     if ((tmp = t + minHeight - 1) > b)
  107.         if (tmp > ti.screenheight)
  108.             b = ti.screenheight;
  109.         else
  110.             b = tmp;
  111.     if ((tmp = b - minHeight + 1) < t)
  112.         if (tmp < 1)
  113.             return 0;
  114.         else
  115.             t = tmp;
  116.     left = l; top = t; right = r; bottom = b;
  117.     return 1;
  118. }
  119.  
  120.  
  121. void TextFraming::vline(int x, int top, int bottom, int attr,
  122.     enum LSTYLE ls)
  123. {
  124.     int i, len;
  125.  
  126.     attr <<= 8;
  127.     attr |= lnChar(ls,VERTICAL);
  128.     if ((len = (bottom - top + 1)) > MAX_TF_BUF)
  129.         len = MAX_TF_BUF;
  130.     for (i = 0; i < len; i++)
  131.         buf[i] = attr;
  132.     puttext(x,top,x,bottom,buf);
  133. }
  134.  
  135. void TextFraming::hline(int y, int left, int right, int attr,
  136.     enum LSTYLE ls)
  137. {
  138.     int i, len;
  139.  
  140.     attr <<= 8;
  141.     attr |= lnChar(ls,HORIZONAL);
  142.     if ((len = (right - left + 1)) > MAX_TF_BUF)
  143.         len = MAX_TF_BUF;
  144.     for (i = 0; i < len; i++)
  145.         buf[i] = attr;
  146.     puttext(left,y,right,y,buf);
  147. }
  148.  
  149. void TextFraming::box(int left, int top, int right,
  150.     int bottom, int attr, enum BSTYLE bs)
  151. {
  152.     enum LSTYLE ls = (enum LSTYLE) (bs % LSTYLES);
  153.     vline(left,top,bottom,attr,ls);
  154.     vline(right,top,bottom,attr,ls);
  155.     ls = ((bs % 3)? DOUBLE : SINGLE);
  156.     hline(top,left,right,attr,ls);
  157.     hline(bottom,left,right,attr,ls);
  158.     attr <<= 8;
  159.     buf[0] = attr | bxChar(bs,UPPER_LEFT);
  160.     puttext(left,top,left,top,buf);
  161.     buf[0] = attr | bxChar(bs,UPPER_RIGHT);
  162.     puttext(right,top,right,top,buf);
  163.     buf[0] = attr | bxChar(bs,LOWER_RIGHT);
  164.     puttext(right,bottom,right,bottom,buf);
  165.     buf[0] = attr | bxChar(bs,LOWER_LEFT);
  166.     puttext(left,bottom,left,bottom,buf);
  167. }
  168.